package com.huawei.hwCloudJs.d;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
import android.text.TextUtils;
import android.util.Log;
import com.huawei.hms.framework.network.util.HttpUtils;
import java.io.Closeable;
import java.io.IOException;
import java.util.List;

public class f {
    private static final String a = "Utils";
    private static int b = 0;

    public static int a() {
        int i = b;
        b = i + 1;
        return i;
    }

    public static String a(Context context, String str) {
        String str2 = "";
        if (context == null) {
            return str2;
        }
        try {
            PackageManager packageManager = context.getPackageManager();
            return packageManager != null ? packageManager.getPackageInfo(str, 0).versionName : str2;
        } catch (NameNotFoundException e) {
            Log.e(a, " NameNotFoundException .. ");
            return str2;
        }
    }

    public static void a(Context context) {
        context.startActivity(new Intent("android.settings.SETTINGS"));
    }

    public static void a(Closeable closeable) {
        if (closeable != null) {
            try {
                closeable.close();
            } catch (IOException e) {
                Log.e(a, "closeStream IOException");
            }
        }
    }

    public static boolean a(String str) {
        return TextUtils.isEmpty(str) ? false : str.startsWith(HttpUtils.HTTP_PREFIX) || str.startsWith("https://");
    }

    public static int b(Context context, String str) {
        if (context == null) {
            return 0;
        }
        try {
            PackageManager packageManager = context.getPackageManager();
            return packageManager != null ? packageManager.getPackageInfo(str, 0).versionCode : 0;
        } catch (NameNotFoundException e) {
            Log.e(a, " NameNotFoundException .. ");
            return 0;
        }
    }

    public static String b(Context context) {
        return context.getPackageName();
    }

    public static boolean b() {
        return b("com.huawei.android.app.ActionBarEx");
    }

    private static boolean b(String str) {
        try {
            Class.forName(str);
            return true;
        } catch (ClassNotFoundException e) {
            return false;
        }
    }

    public static boolean c(Context context, String str) {
        if (context == null || str == null) {
            Log.e(a, "packageInstalled null==context fail!");
            return false;
        }
        PackageManager packageManager = context.getPackageManager();
        if (packageManager != null) {
            List<PackageInfo> installedPackages = packageManager.getInstalledPackages(0);
            if (installedPackages != null) {
                for (PackageInfo packageInfo : installedPackages) {
                    if (str.equals(packageInfo.packageName)) {
                        Log.e(a, "packageInstalled true!");
                        return true;
                    }
                }
            }
        }
        Log.e(a, "packageInstalled false!");
        return false;
    }

    public static boolean d(Context context, String str) {
        if (context == null || TextUtils.isEmpty(str)) {
            return false;
        }
        String str2 = "308204b53082039da003020102020900f20456ab964fa0f0300d06092a864886f70d0101050500308198310b300906035504061302434e31123010060355040813094775616e67646f6e6731123010060355040713095368656e677a68656e310f300d060355040a130648756177656931183016060355040b130f5465726d696e616c436f6d70616e79311430120603550403130b416e64726f69645465616d3120301e06092a864886f70d01090116116d6f62696c65406875617765692e636f6d301e170d3131303532353036313034395a170d3336303531383036313034395a308198310b300906035504061302434e31123010060355040813094775616e67646f6e6731123010060355040713095368656e677a68656e310f300d060355040a130648756177656931183016060355040b130f5465726d696e616c436f6d70616e79311430120603550403130b416e64726f69645465616d3120301e06092a864886f70d01090116116d6f62696c65406875617765692e636f6d30820120300d06092a864886f70d01010105000382010d00308201080282010100e02c5ab97a2b3a8a5996223cde06b82b2d4ff5b15caf65b860d5c7a3d68995ab08620bb75a22fe7673a8a1aba03e17b651d1fc4d5cbdbae9e73eeeaf5a1d4d2fb73e7000231e0db2166d0fc5dd97e705fd66546c9da38ed4efa2cccdd238ad32e39821242b0195df01d9b97242dbf209eda8e446e043244b84e6bfca79d7bb3c1924cdd248edbd600eff8f73001a89a4c663db8970e3288b9431524c361e853b8fa29e04e61ebe6fbdbd87cdbd3eeb47b027b5851bdeaa13a23f43967a030e747ea432652cbb34fdde61049bf5060c813fb0e93f6bad9d36f4d4551195ea3bb49e9201aa6df975ae169e214905de2579d7cc3c3eac4594b14ac19d7e39c5c267020103a38201003081fd301d0603551d0e041604143ec690de811bc39e51a30301ad23cf3006d67de03081cd0603551d230481c53081c280143ec690de811bc39e51a30301ad23cf3006d67de0a1819ea4819b308198310b300906035504061302434e31123010060355040813094775616e67646f6e6731123010060355040713095368656e677a68656e310f300d060355040a130648756177656931183016060355040b130f5465726d696e616c436f6d70616e79311430120603550403130b416e64726f69645465616d3120301e06092a864886f70d01090116116d6f62696c65406875617765692e636f6d820900f20456ab964fa0f0300c0603551d13040530030101ff300d06092a864886f70d010105050003820101006dad2fc590cf0079ac4ce0865a884311dc16ad83275a2b0302405776dd1d1f704a29993c8a134a8dfdd54c59151a06155612dbd300646eacfc9f64fac2e352709b0359f756af96c1f56495304e72287be4798a0433356cbccdd8d57cde1f7ff1c004cb962ad595b1da22ef204de144908861bba968e0c74381e119c772b2cf22c3d0c8325a9f31c9787b156c94771af66f4ffb1ad996c3fbe764f3bc50b7a2643c23372612f2509946a03badfbfea61f8e3d28923385bbc00875acec99b6d92ac468f0dc50c0997ff409e3a25dc8d966c20d588a9713ff217e2de49457a32cf23df1af58f4bcdd94a8f26bc1c90c5a5183db64d46353dd4610478c77f2c89988";
        PackageManager packageManager = context.getPackageManager();
        if (packageManager == null) {
            Log.e(a, "isCorrectSign PackageManager null!");
            return false;
        }
        try {
            PackageInfo packageInfo = packageManager.getPackageInfo(str, 64);
            if (packageInfo == null) {
                Log.e(a, "isCorrectSign PackageInfo null!");
                return false;
            }
            Signature[] signatureArr = packageInfo.signatures;
            if (signatureArr == null) {
                Log.e(a, "isCorrectSign signs null!");
                return false;
            }
            for (Signature toCharsString : signatureArr) {
                if ("308204b53082039da003020102020900f20456ab964fa0f0300d06092a864886f70d0101050500308198310b300906035504061302434e31123010060355040813094775616e67646f6e6731123010060355040713095368656e677a68656e310f300d060355040a130648756177656931183016060355040b130f5465726d696e616c436f6d70616e79311430120603550403130b416e64726f69645465616d3120301e06092a864886f70d01090116116d6f62696c65406875617765692e636f6d301e170d3131303532353036313034395a170d3336303531383036313034395a308198310b300906035504061302434e31123010060355040813094775616e67646f6e6731123010060355040713095368656e677a68656e310f300d060355040a130648756177656931183016060355040b130f5465726d696e616c436f6d70616e79311430120603550403130b416e64726f69645465616d3120301e06092a864886f70d01090116116d6f62696c65406875617765692e636f6d30820120300d06092a864886f70d01010105000382010d00308201080282010100e02c5ab97a2b3a8a5996223cde06b82b2d4ff5b15caf65b860d5c7a3d68995ab08620bb75a22fe7673a8a1aba03e17b651d1fc4d5cbdbae9e73eeeaf5a1d4d2fb73e7000231e0db2166d0fc5dd97e705fd66546c9da38ed4efa2cccdd238ad32e39821242b0195df01d9b97242dbf209eda8e446e043244b84e6bfca79d7bb3c1924cdd248edbd600eff8f73001a89a4c663db8970e3288b9431524c361e853b8fa29e04e61ebe6fbdbd87cdbd3eeb47b027b5851bdeaa13a23f43967a030e747ea432652cbb34fdde61049bf5060c813fb0e93f6bad9d36f4d4551195ea3bb49e9201aa6df975ae169e214905de2579d7cc3c3eac4594b14ac19d7e39c5c267020103a38201003081fd301d0603551d0e041604143ec690de811bc39e51a30301ad23cf3006d67de03081cd0603551d230481c53081c280143ec690de811bc39e51a30301ad23cf3006d67de0a1819ea4819b308198310b300906035504061302434e31123010060355040813094775616e67646f6e6731123010060355040713095368656e677a68656e310f300d060355040a130648756177656931183016060355040b130f5465726d696e616c436f6d70616e79311430120603550403130b416e64726f69645465616d3120301e06092a864886f70d01090116116d6f62696c65406875617765692e636f6d820900f20456ab964fa0f0300c0603551d13040530030101ff300d06092a864886f70d010105050003820101006dad2fc590cf0079ac4ce0865a884311dc16ad83275a2b0302405776dd1d1f704a29993c8a134a8dfdd54c59151a06155612dbd300646eacfc9f64fac2e352709b0359f756af96c1f56495304e72287be4798a0433356cbccdd8d57cde1f7ff1c004cb962ad595b1da22ef204de144908861bba968e0c74381e119c772b2cf22c3d0c8325a9f31c9787b156c94771af66f4ffb1ad996c3fbe764f3bc50b7a2643c23372612f2509946a03badfbfea61f8e3d28923385bbc00875acec99b6d92ac468f0dc50c0997ff409e3a25dc8d966c20d588a9713ff217e2de49457a32cf23df1af58f4bcdd94a8f26bc1c90c5a5183db64d46353dd4610478c77f2c89988".equals(toCharsString.toCharsString())) {
                    return true;
                }
            }
            return false;
        } catch (NameNotFoundException e) {
            Log.e(a, "isCorrectSign PackageManager.NameNotFoundException!");
            return false;
        }
    }
}
